perm filename HOW[L70,TES] blob
sn#009938 filedate 1972-05-14 generic text, type T, neo UTF8
00100 USING MLISP2
00200
00300 MLISP2 has most of the facilities of MLISP. It does NOT have DEFINE,
00400 vector operations, MTRANS, and certain other special features of MLISP.
00500 MLISP2 does offer backtracking.
00600
00700 A special version of MLISP2 is available for this class to solve the
00800 two towers problem. Here is how to use it.
00900
01000 (1) Prepare a file TOWER on your disk area. It should have the
01100 declarations of two functions, TOWER and TWOTOWERS. It may also have
01200 other function declarations and "Initiallize" Statements (see
01300 below). The last line of the file should have the word:
01400 _EOF_
01500 The functions should NOT be within a block, as they are in MLISP.
01600
01700 NOTE: If you are on a teletype, SOS recognizes the following
01800 equivalents:
01900 _ ?9
02000 { ?[
02100 } ?]
02200
02300 INITIALLIZE STATEMENT
02400 Assignment statements (SETQ) in MLISP2 are undone during
02500 backtracking. Furthermore, assignment statements standing alone
02600 in your file TOWER will be undone as soon as they are done. To
02700 make an irreversible assignment, use the Initiallize statement:
02800
02900 X{NIL} ← <2, 3, 4> ;
03000
03100 This sets X to the list (2 3 4).
03200
03300 Sample file TOWER (the functions are entirely erroneous):
03400
03500 - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
03600
03700
03800
03900
04000 EXPR TOWER(N) ; <IF N ≤ 5 THEN CHOICE(N) ELSE FAILURE()> ;
04100
04200 EXPR TWOTOWERS(N, M) ;
04300 ASSOC('ROSES, FOO) CONS MAPCAR(TOWER(N), TOWER(M)) ;
04400
04500 FOO{NIL} ← '((ROSES RED) (VIOLETS BLUE)) ;
04600
04700 _EOF_
00100 (2) Imitate the conversation depicted below to test your functions.
00200
00300 .R TOWER
00400
00500 *(TRANSLATE)
00600 TRANSLATING FROM FILE: TOWER
00700
00800
00900 *****
01000 TOWER TWOTOWERS
01100 *****
01200
01300 TRANSLATION TIME: 0 MACHINE SECONDS, 0 REAL SECONDS
01400
01500 186 STATE STACK CELLS USED
01600 23 TOKEN STACK CELLS USED
01700
01800 YOU ARE ABOUT TO TYPE TO MLISP2, E.G.: PROBLEM(1);
01900
02000
02100 *****
02200 *PROBLEM(1);
02300 THESE ARE THE BLOCKS YOU HAVE:
02400
02500 (1 2 4)
02600 *** *TEST(1);
02700 (TOWER 1) = (1)
02800
02900
03000 *** *TEST(10);
03100 (TOWER 10) = FAILURE
03200
03300
03400 *** *PROBLEM(5);
03500 THESE ARE THE BLOCKS YOU HAVE:
03600
03700 (15 14 2 5 8 11 14)
03800 *** *TEST(20,60);
03900 (TWOTOWERS 20 60) = FAILURE
04000
04100
04200 *** *TEST();
04300 ANSWERS WILL NOT APPEAR ON THE TERMINAL.
04400 ANSWERS RECORDED FOR GRADER
04500
04600 *** *↑C
04700 ↑C
04800
04900 .
00100 Here is an explanation of the various functions you may call
00200 during your test.
00300
00400 (TRANSLATE)
00500 Translates the functions on file TOWER and executes the
00600 Initialize Statements, if any.
00700
00800 If there are syntax errors, they will show up in one of two
00900 ways:
01000
01100 (a) If you are lucky, "SYNTAX ERROR" will type out,
01200 and a blown up image of the statement that
01300 caused the error.
01400 (b) One of your functions has an extra END or
01500 missing " or some such thing -- the effect is
01600 that the printout will not be complete. For
01700 example, the names of one or more of your
01800 functions may not print out during translation,
01900 or you will be returned to the top level of LISP.
02000
02100 To correct syntax errors, return to the editor.
02200
02300 When translation is complete, TRANSLATE automatically
02400 calls (PARSE)
02500
02600 (PARSE)
02700 This lets you type to MLISP2 instead of to LISP.
02800 When talking to MLISP2, call the function (FOO X Y) by:
02900 FOO(X, Y);
03000 To find out the value of X, type:
03100 X;
03200 To change the value of X, use an Initialize Statement:
03300 X{NIL} ← Y ;
03400 Remember that the LISP top-level loop is:
03500 (PRINT (EVAL (READ)))
03600 The MLISP2 top-level loop is:
03700 Undo(PRINT(EVAL(Translation(input))));
03800 I.E., it inputs one MLISP2 expression, translates it
03900 to LISP, EVALs it, PRINTs the result, and Undoes
04000 all "reversible" side effects since input began.
04100
04200 "Reversible" Side Effects
04300 X ← Y ; PUT(X, Z, P) ;
04400 Function entries & exits
04500
04600 "Irreversible" Side Effects
04700 X{NIL} ← Y ; PUTPROP(X, Z, P) ;
04800 Array stores, RPLACA, RPLACD, input, output
04900
05000 FAILURE();
05100 This backs up to the last CHOICE(n), and Undoes
05200 "reversible" side effects on the way.
00100 PROBLEM(n);
00200 Where n=1, 2, 3, 4, or 5.
00300 This initiallizes BLOCKS to one of five prepared lists
00400 and makes other vital preparations for testing
00500 your functions.
00600
00700 TEST(a);
00800 Where `a' is an integer.
00900 This calls your function TOWER(a). If you call it
01000 yourself, strange things may happen. TEST
01100 re-initializes BLOCKS before it calls TOWER,
01200 in case it has been changed by earlier calls.
01300 TEST prints the arguments and value of your function.
01400 If TOWER should completely fail, TEST prints FAILURE.
01500
01600 TEST(a, b);
01700 Where `a' and `b' are integers.
01800 This calls your function TWOTOWERS(a, b) as above.
01900
02000 TEST() ;
02100 This calls both your functions with various
02200 prepared sets of arguments.
02300
02400 NOTE: For PROBLEM(5); TEST() will not print the
02500 results on the terminal, but instead will
02600 report them to the grader. Do this after
02700 you have tested your functions extensively.
02800 The grader will only see the last set of
02900 results that are reported before 11:00 AM Friday.
03000
03100 ALSO Hand in a printout of your functions if possible.
03200 If impossible, leave them on the file TOWER.
03300
03400 π CR
03500 CONTROL-G CR
03600 bell CR
03700 Depending on what terminal you are using.
03800 This brings you back to LISP. To return to MLISP2,
03900 do a (PARSE)
00100 (TRACE ...)
00200 Call it from LISP, not from MLISP2, then return to
00300 MLISP2 to test your functions.
00400
00500 (UNTRACE ...)
00600 Same.
00700
00800 ERRORS!
00900 MLISP2 Syntax errors will be noted and you will be
01000 given a chance to retype the statement.
01100
01200 LISP errors will bring you to LISP. Type
01300 π (or CONTROL-G or bell) and CR and (PARSE) and CR
01400 to get back to MLISP2.
01500
01600 WHEN IN DOUBT
01700 Type π CR (PARSE) CR.
01800
01900 CONTROL-C and R TOWER again (i.e., start over)
02000
02100 Check your program.
02200
02300 Did you forget to type ";" to MLISP2?
02400
02500 Follow the protocall of the sample run.
02600
02700 See your TA.
02800
02900 If TA can't help, call Larry Tesler x4971.